package com.qf.agro.service.crop.impl;

/**
 * 愿机魂与你同在
 * 编写者：📕从来不学习
 * projectName:smart-agriculture-parent
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.mapper.crop.CropMapper;
import com.qf.agro.pojo.crop.Crop;
import com.qf.agro.service.crop.CropService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author 86134
 * @Date 2023/7/5 14:43:42
 * @Description 农作物业务层接口实现类
 */
@Service
@Transactional
public class CropServiceImpl implements CropService {

    @Autowired
    private CropMapper cropMapper;

    /**
     * 分页查询农作物
     *
     * @param pageNum
     * @param pageSize
     * @param name
     * @return Page<Company>
     * @author 📕从来不学习
     * @date 2023/7/5 14:46
     */
    @Override
    public Page<Crop> findPage(Integer pageNum, Integer pageSize, String name,String facilitiesId) {
        Page<Crop> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Crop> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(name), Crop::getName, name);
        wrapper.eq(StringUtils.isNotEmpty(facilitiesId),Crop::getFacilitiesId,facilitiesId);
        page = cropMapper.selectPage(page, wrapper);
        return page;
    }

    /**
     * 删除农作物
     *
     * @param id
     * @author 📕从来不学习
     * @date 2023/7/5 14:47
     */
    @Override
    public void delete(Long id) {
        cropMapper.deleteById(id);
    }

    @Override
    public void save(Crop crop) {
        cropMapper.insert(crop);
    }

    @Override
    public void update(Crop crop) {
        cropMapper.updateById(crop);
    }
}
